//
//  EnergyNumView.m
//  Ginix
//
//  Created by 冯志强 on 2025/2/26.
//

#import "EnergyNumView.h"

@interface EnergyNumView()
@property (nonatomic,strong) UIImageView * numView;
@property (nonatomic,strong) UILabel * infoLabel;
@property (nonatomic,strong) UIProgressView * progressView;
@property (nonatomic,strong) UIButton * enterBtn;
@property (nonatomic,strong) EnergyInfoModel * model;
@end

@implementation EnergyNumView

-(instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        [self setSubViewLayout];
    }
    return self;
}

-(void)setSubViewLayout{
    
    [self addSubview:self.numView];
    [_numView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(@0);
    }];
    [self.numView addSubview:self.infoLabel];
    [_infoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(44 * FMScaleX);
        make.top.mas_offset(18 * FMScaleX);
    }];
    [self.numView addSubview:self.progressView];
    [_progressView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.infoLabel);
        make.top.equalTo(self.infoLabel.mas_bottom).offset(2 * FMScaleX);
        make.size.mas_offset(CGSizeMake(180 * FMScaleX, 6 * FMScaleX));
    }];
    [self.numView addSubview:self.enterBtn];
    [_enterBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_offset(CGSizeMake(30 * FMScaleX, 16 * FMScaleX));
        make.right.mas_offset(-30* FMScaleX);
        make.bottom.mas_offset(-12 * FMScaleX);
    }];
}

-(void)setInfoModel:(EnergyInfoModel *)infoModel{
    
    if (UserInfoModel.shareInstance.userModel.isBind != 1) {
        return;
    }
    self.model = infoModel;
    self.infoLabel.text = [NSString stringWithFormat:@"体力（%.0f/100)",infoModel.elvesDetail.physicalStrength];
    self.progressView.progress = (infoModel.elvesDetail.physicalStrength / 100);
}

-(void)enterAction{
    
    if (UserInfoModel.shareInstance.userModel.isBind != 1) {
        FhudShowStr(@"您还没有草药精灵，无法恢复体力")
        return;
    }else{
        if (self.enterdBtnBlock) {
            self.enterdBtnBlock(self.model.elvesDetail.pickerId);
        }
    }
}

-(UIImageView *)numView{
    
    if(!_numView){
        _numView = [[UIImageView alloc]init];
        _numView.image = [UIImage imageNamed:@"Energy_num_icon"];
        _numView.userInteractionEnabled = YES;
    }
    return _numView;
}
-(UILabel *)infoLabel{
    
    if (!_infoLabel) {
        _infoLabel = [[UILabel alloc]init];
        _infoLabel.textColor = UIColor.whiteColor;
        _infoLabel.font = Regular(10);
        _infoLabel.text = @"体力  ";
    }
    return _infoLabel;
}
-(UIProgressView *)progressView{
    
    if (!_progressView) {
        _progressView = [[UIProgressView alloc]init];
        _progressView.progressTintColor = RDRGB(0xD3B587);
        _progressView.trackTintColor = RDRGB(0x714933);
        [_progressView setCornerRadius:3 * FMScaleX borderWidth:1 borderColor:RDRGB(0xCC9F86)];
//        _progressView.progress = 0.3;
    }
    return _progressView;
}

-(UIButton *)enterBtn{
    
    if (!_enterBtn) {
        _enterBtn = [[UIButton alloc]init];
        [_enterBtn setTitle:@"恢复" forState:UIControlStateNormal];
        [_enterBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
        [_enterBtn setBackgroundColor:RDRGBA(0xffffff, 0.29)];
        [_enterBtn setCornerRadius:8 * FMScaleX];
        _enterBtn.titleLabel.font = Regular(10);
        [_enterBtn addTarget:self action:@selector(enterAction ) forControlEvents:UIControlEventTouchUpInside];
    }
    return _enterBtn ;
}


@end
